
$(function(){
	$("#clear").click(function(){
		localStorage.clear();
	})
	var arrs=[],n;
	for(var i=1000;i<=1200;i++){
		arrs.push(i);
		if(i==1200){
			for(var i=2000;i<=2200;i++){
				arrs.push(i);
				if(i == 2200){
					for(var i=3000;i<=3200;i++){
						arrs.push(i);
					}
				}
			}
		}
	}
	var str=JSON.stringify(arrs)
	localStorage.pond=str;
	var prize=JSON.parse(localStorage.pond));
		n=prize.length+1;

	$("#normal").click(function(){
		$(this).addClass("start");
		$(this).siblings().removeClass("start");
			$("div.prize-number").html("");
			$("#grand").css("background-image","url(img/grandprizeOff.png)");
			$("#normal").css("background-image","url(img/normalprizeOn.png)");
			$("#third").css("background-image","url(img/thirdprizeOff.png)");
			$("#second").css("background-image","url(img/secondprizeOff.png)");
			$("#first").css("background-image","url(img/firstprizeOff.png)");
		
	});
	
	$("#third").click(function(){
		$(this).addClass("start");
		$(this).siblings().removeClass("start");
			$("div.prize-number").html("");
			$("#grand").css("background-image","url(img/grandprizeOff.png)");
			$("#normal").css("background-image","url(img/normalprizeOff.png)");
			$("#third").css("background-image","url(img/thirdprizeOn.png)");
			$("#second").css("background-image","url(img/secondprizeOff.png)");
			$("#first").css("background-image","url(img/firstprizeOff.png)");
	});
	$("#second").click(function(){
		$(this).addClass("start");
		$(this).siblings().removeClass("start");
			$("div.prize-number").html("");
			$("#grand").css("background-image","url(img/grandprizeOff.png)");
			$("#normal").css("background-image","url(img/normalprizeOff.png)");
			$("#third").css("background-image","url(img/thirdprizeOff.png)");
			$("#second").css("background-image","url(img/secondprizeOn.png)");
			$("#first").css("background-image","url(img/firstprizeOff.png)");
	});
	$("#first").click(function(){
		$(this).addClass("start");
		$(this).siblings().removeClass("start");
			$("div.prize-number").html("");
			$("#grand").css("background-image","url(img/grandprizeOff.png)");
			$("#normal").css("background-image","url(img/normalprizeOff.png)");
			$("#third").css("background-image","url(img/thirdprizeOff.png)");
			$("#second").css("background-image","url(img/secondprizeOff.png)");
			$("#first").css("background-image","url(img/firstprizeOn.png)");
	});
	$("#grand").click(function(){
			$(this).addClass("start");
			$(this).siblings().removeClass("start");
			$("div.prize-number").html("");
			$("#grand").css("background-image","url(img/grandprizeOn.png)");
			$("#normal").css("background-image","url(img/normalprizeOff.png)");
			$("#third").css("background-image","url(img/thirdprizeOff.png)");
			$("#second").css("background-image","url(img/secondprizeOff.png)");
			$("#first").css("background-image","url(img/firstprizeOff.png)");
	});
	$("#start").click(function(){
		$(this).attr("disabled",true);
		$("div.prize button").attr("disabled",true);
		if($("#grand").hasClass("start")){
			start(1);	
		}
		if($("#first").hasClass("start")){
			start(3)
		}
		if($("#second").hasClass("start")){
			var i=0;
			start(10)
		}
		if($("#third").hasClass("start")){
			var i=0;
			start(25)
		}
		if($("#normal").hasClass("start")){
			var i=0;
			start(50)
		}
	})
	$("#again").click(function(){
		$("#start").attr("disabled",false)
		$("div.prize button").attr("disabled",false);
	})
	var array=[];
	function start(index){
		var number="",x=0;
		var timer1=setInterval(function(){
			console.log("x="+x)
			if(x == index){
				clearInterval(timer1);
			}else{
				if(x == 0){
					var n=parseInt(Math.random()*4000);
					array.push(n);
					console.log(array);
					$("#thousand").text(n);
					$("div.prize-number").append("<span class='normal'>"+n+"</span>");	
				}
				if(x>0){
					console.log(array);
					var n=parseInt(Math.random()*4000)+1000;	
					if(isCon(array,n) == true){
						x--;
					}
					if(isCon(array,n) == false){
						var n=parseInt(Math.random()*4000)+1000;
						array.push(n);
						console.log(array);
						$("#thousand").text(n);
						$("div.prize-number").append("<span class='normal'>"+n+"</span>");
					}
				}
				
			}
			x=x+1;
		},500)
	}
	function isCon(arr,val){
		for(var i=0; i<arr.length; i++){
			if(arr[i] == val)
			return true;
			}
			return false;
	}

})